Unable to import Spring Security #Secured Annotation into Grails 3 - spring

I am currently following the Spring Security 3.0.0.M1 plugin tutorial for Grails here and I appear to be stuck on Step 8. Using the statement import grails.plugin.springsecurity.annotation.Secured does not work because Grails cannot resolve the package name. I know that Spring Security for Grails 3 is in its infancy, but has anyone been able to get past this step yet? For reference, here is my SecureController class (with a another import that also does not work):
package ldaptest.controllers
import grails.plugin.springsecurity.annotation.Secured;
import org.springframework.security.access.annotation.Secured;
#Secured('ROLE_ADMIN')
class SecureController {
def index() {
render 'Secure access only'
}
}

I may found a solution:
Create a "lib" folder e.g. inside your "grails-app" directory.
Download the SpringSecurityCore JAR from here and move it into the lib directory
Add gradle dependency:
compile files('lib/spring-security-core-3.0.0.M1.jar')
Hope this helps.
Greetings

I had:3,1,1 the save problem with my application. I solved it by adding as a library to my project. However I had to change import package to make it work.
import org.springframework.security.access.annotation.Secured
I am using IntelliJ IDEA, I just has to search the maven repo for the spring-security-core:3.1.1.
In IntelliJ you do : File > Project Structure > Libraries > Add > From Maven Repository. Then do the search according to the version of "spring-security-core" you want to use.

Related

Upgraded to grails 3 and now get unable to resolve class org.codehaus.groovy.grails.web.servlet.mvc.GrailsParameterMap

unable to resolve class org.codehaus.groovy.grails.web.servlet.mvc.GrailsParameterMap
# line 4, column 1.
import org.codehaus.groovy.grails.web.servlet.mvc.GrailsParameterMap
This happened when I upgraded grails from 2.2.4 to 3.1.3.
Is there some new place I need to import this too? Or is there a dependency I need to add to my gradle build file?
See step 5 on this page, https://docs.grails.org/3.0.x/guide/upgrading.html
Step 5 - Modify Package Imports In Grails 3.x all internal APIs can be
found in the org.grails package and public facing APIs in the grails
package. The org.codehaus.groovy.grails package no longer exists.
All package declaration in sources should be modified for the new
location of the respective classes. Example
org.codehaus.groovy.grails.commons.GrailsApplication is now
grails.core.GrailsApplication.

Import java class to Jsp in Maven project

I have a project in IDE, so I made a new project in Maven. I copy all the files and classes, and I fill the pom.xml.
This is OK, but the problem is in JSP,eclipse dont find the imported clases.
<%#page import="modelos.Mascota"%>
This import for example cant be resolved.
What I'm doing wrong?
All my java classes are in:
\src\main\resources
And jsp files in:
src\main\webapp
Your .java files must be in
\src\main\java
check your dependencies for the class whether it is exist or not
modelos.Mascota

Missing IBM Websphere classes for SSO (com.ibm.jca.idtoken)

I am trying to enable SSO on a WAS 8.5, which is installed on an AS400, and for this I need to use the following classes in java:
import com.ibm.eim.token.IdentityToken;
import com.ibm.jca.idtoken.ConnectionFactoryImpl;
import com.ibm.jca.idtoken.ConnectionSpecImpl;
import com.ibm.jca.idtoken.IdentityTokenFactory;
I found the package com.ibm.eim in \QIBM\ProdData\OS400\security\eim on the WAS server. However, I cannot find the package com.ibm.jca.idtoken in the file system nor on the IBM Knowledge Center website either. Where can I get it ?
Okay I finally found it. It is here in a jar in a jar in a rar file :
com.ibm.jca.idtoken:
\QIBM\ProdData\OS400\security\eim\idTokenRA.rar\idTokenRA.jar\com\ibm\jca\idtoken\
com.ibm.eim.token:
\QIBM\ProdData\OS400\security\eim\idTokenRA.rar\idToken.jar\com\ibm\eim\token\

Import an Maven dependency (Example Jsoup.jar)

I have a generally understanding Problem with the Maven-Dependency in Grails 2.3.8.
I want to Import jsoup - functionality into my Project.
Therefore I did this in my BuildConfig.groovy:
dependencies {
.
.
/// jsoup
compile "org.jsoup:jsoup:1.7.3"
}
All is okay. Grails downloads the jar File into my local repo
C:\Users\xxx\.m2\repository\org\jsoup\jsoup\1.7.3
Now my confusion. I thougt all is done and i can write my code against Jsoup but this is wrong. I have to
copy the jar file into the Grails - lib Folder
set up the buildpath for Jsoup.jar
do a "grails compile"
Is this the right way? Why do i config dependencies when grails doesnt use them? It seems there is a plugin (compile ":html-cleaner:0.2") where Jsoup is included but when i need Jsoup i use Jsoup and not html-cleaner.
When i did this without my steps i got an Compiler Error:
package f
import grails.transaction.Transactional
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document
/***
*
* #author MG
*
*/
//#Transactional
class xyService {
def getXyFromIndex(String searchKeyword) {
def html = ""
Document doc = Jsoup.parse(html);
}
}
==> 'Groovy:unable to resolve class org.jsoup.nodes.Document' -GGTS 3.5.1
You don't need to copy jar it should automatically get copied either by ivy or maven. Maven is recommended so in BuildConfig.groovy change the resolver value to maven like below. Now when you start your application all jar will get copied to .m2 directory.
grails.project.dependency.resolver = "maven"
Did you try to import JSoup at the top of your file ?
import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import org.jsoup.select.Elements
import org.jsoup.parser.Tag
#Transactional
class myClass {
}

Grails Spring Core Security Plugin - Unable to Resolve Classes

I'm using Grails 2.2.2 and I've already installed spring-security-core-2.0-RC2, by adding the below lines in my BuildConfig.groovy file:
Under the plugins:
compile ':spring-security-core:2.0-RC2'
Under Repositories:
mavenRepo 'http://repo.spring.io/milestone'
The plugin was installed successfully and I've created the security Domains and Controllers using s2-quickstart script.
Now, I've updated one of my controllers with the below code:
import grails.plugins.springsecurity.Secured
#Secured(['ROLE_ADMIN'])
However when I try to run the application I get the below error:
| Error Compilation error: startup failed: C:\workspace\SW
Development\Production\MyGrailsApp\safami\grails-app\controllers\safami\InfoPageAdminController.groovy:
4: unable to resolve class grails.plugins.springsecurity.Secured #
line 4, column 1. import grails.plugins.springsecurity.Secured
I'm new to Grails and I need your detailed solution.
The annotation was moved to a different package - change
import grails.plugins.springsecurity.Secured
to
import grails.plugin.springsecurity.annotation.Secured

Resources