org.apache.shiro.io.Serializer Java Examples
The following examples show how to use
org.apache.shiro.io.Serializer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShiroTest.java From EasyEE with MIT License | 6 votes |
public static void main(String[] args) { String base64="zGkG0zevFbnIioooS3MfnnbWeBUeiZrScKVJms0CZAdJ2MYTddPkvBHGmMhvgdKA5QJk8FSb9T1Y1tFlUnnCsIvcK+iX4cfrwD7voGdU5bW9AWjwNvl3BDrAgRf+hvjrI3T5nBTFeW7uI6GzfFrIx92qER9lQ97g19Dn555uwIzf0ULvc8jICZTraLLrf2avh1hy2kUJJblO6u5IHiBbAXBNitZ6W1yjLEWmSFnb+EsEWAGB3WwV1u1HZO045LB4G57UIH4QGM0xfJjWWeahiTS4j9IAEJBbghwfL1A5pdzFiXJzzA5GF85vtP+6jLwQfGaQJyv35PvNNsDmCqFe8eUSBLji5z5y/y+yKfZk9izXiEvFjKQ5kqMqKfLMp+Vn5OuO+syc4CfJL4PLI16vwVUPV1EWAzyxUhK7DtD5OMVcLPwVtwZ11dG88wkZtjXvBymLyGCj5/Tk8gTWYsdcNKD5i8WvbMLT45S4iWsZxa/5offIiCipkkqoqvxCppJLTzBoaR/wlqoa1Bc/cvpijiJTIbSCj+iFloQRdax1mMQ"; base64 = ensurePadding(base64); byte[] decoded = Base64.decode(base64); byte[] serialized = decoded; CipherService cipherService = new AesCipherService(); if (cipherService != null) { ByteSource byteSource = cipherService.decrypt(decoded, new byte[]{-112, -15, -2, 108, -116, 100, -28, 61, -99, 121, -104, -120, -59, -58, -102, 104}); serialized = byteSource.getBytes(); } Serializer<PrincipalCollection> serializer = new DefaultSerializer<PrincipalCollection>(); ; System.out.println(serializer.deserialize(serialized)); SimplePrincipalCollection p=(SimplePrincipalCollection) serializer.deserialize(serialized); System.out.println(p.getPrimaryPrincipal()); System.out.println(p.getRealmNames()); System.out.println(p); }
Example #2
Source File: ShiroTest.java From EasyEE with MIT License | 6 votes |
public static void main(String[] args) { String base64="zGkG0zevFbnIioooS3MfnnbWeBUeiZrScKVJms0CZAdJ2MYTddPkvBHGmMhvgdKA5QJk8FSb9T1Y1tFlUnnCsIvcK+iX4cfrwD7voGdU5bW9AWjwNvl3BDrAgRf+hvjrI3T5nBTFeW7uI6GzfFrIx92qER9lQ97g19Dn555uwIzf0ULvc8jICZTraLLrf2avh1hy2kUJJblO6u5IHiBbAXBNitZ6W1yjLEWmSFnb+EsEWAGB3WwV1u1HZO045LB4G57UIH4QGM0xfJjWWeahiTS4j9IAEJBbghwfL1A5pdzFiXJzzA5GF85vtP+6jLwQfGaQJyv35PvNNsDmCqFe8eUSBLji5z5y/y+yKfZk9izXiEvFjKQ5kqMqKfLMp+Vn5OuO+syc4CfJL4PLI16vwVUPV1EWAzyxUhK7DtD5OMVcLPwVtwZ11dG88wkZtjXvBymLyGCj5/Tk8gTWYsdcNKD5i8WvbMLT45S4iWsZxa/5offIiCipkkqoqvxCppJLTzBoaR/wlqoa1Bc/cvpijiJTIbSCj+iFloQRdax1mMQ"; base64 = ensurePadding(base64); byte[] decoded = Base64.decode(base64); byte[] serialized = decoded; CipherService cipherService = new AesCipherService(); if (cipherService != null) { ByteSource byteSource = cipherService.decrypt(decoded, new byte[]{-112, -15, -2, 108, -116, 100, -28, 61, -99, 121, -104, -120, -59, -58, -102, 104}); serialized = byteSource.getBytes(); } Serializer<PrincipalCollection> serializer = new DefaultSerializer<PrincipalCollection>(); ; System.out.println(serializer.deserialize(serialized)); SimplePrincipalCollection p=(SimplePrincipalCollection) serializer.deserialize(serialized); System.out.println(p.getPrimaryPrincipal()); System.out.println(p.getRealmNames()); System.out.println(p); }
Example #3
Source File: SecurityModule.java From tapestry-security with Apache License 2.0 | 6 votes |
public static void bind(final ServiceBinder binder) { binder.bind(WebSecurityManager.class, TapestryRealmSecurityManager.class); // TYNAMO-155 It's not enough to identify ModularRealmAuthenticator by it's Authenticator interface only // because Shiro tests if the object is an instanceof LogoutAware to call logout handlers binder.bind(ModularRealmAuthenticator.class); binder.bind(SubjectFactory.class, DefaultWebSubjectFactory.class); binder.bind(HttpServletRequestFilter.class, SecurityConfiguration.class).withId("SecurityConfiguration").withMarker(Security.class); binder.bind(ClassInterceptorsCache.class, ClassInterceptorsCacheImpl.class); binder.bind(SecurityService.class, SecurityServiceImpl.class); binder.bind(SecurityFilterChainFactory.class, SecurityFilterChainFactoryImpl.class); binder.bind(ComponentRequestFilter.class, SecurityComponentRequestFilter.class); binder.bind(SecurityFilterChainHub.class, SecurityFilterChainHubImpl.class); // binder.bind(ShiroExceptionHandler.class); binder.bind(LoginContextService.class, LoginContextServiceImpl.class); binder.bind(Serializer.class, SimplePrincipalSerializer.class); }
Example #4
Source File: SecurityModule.java From tapestry-security with Apache License 2.0 | 5 votes |
@SuppressWarnings({"rawtypes", "unchecked"}) public static RememberMeManager buildRememberMeManager(Serializer serializer, Logger logger, @Symbol(SymbolConstants.HMAC_PASSPHRASE) String hmacPassphrase, @Symbol(SecuritySymbols.REMEMBERME_CIPHERKERY) String rememberMeCipherKey) throws UnsupportedEncodingException { CookieRememberMeManager rememberMeManager = new CookieRememberMeManager(); // the default Shiro serializer produces obnoxiously long cookies rememberMeManager.setSerializer(serializer); // assume properly configured cipher is of the right width (divisable by 16) byte[] cipherKey = Base64.decode(rememberMeCipherKey); if (cipherKey.length <= 0) { if (hmacPassphrase.isEmpty()) { logger .error("Neither symbol '" + SecuritySymbols.REMEMBERME_CIPHERKERY + "' nor '" + SymbolConstants.HMAC_PASSPHRASE + "' is set. Using a random value as the cipher key for encrypting rememberMe information. Cookies will be invalidated when the JVM is restarted"); return rememberMeManager; } logger.warn("Symbol '" + SecuritySymbols.REMEMBERME_CIPHERKERY + "' is not set, using '" + SymbolConstants.HMAC_PASSPHRASE + "' as the cipher. Beware that changing the value will invalidate rememberMe cookies"); if (hmacPassphrase.length() < 16) hmacPassphrase = hmacPassphrase + ("================".substring(hmacPassphrase.length())); cipherKey = hmacPassphrase.getBytes("UTF-8"); if (cipherKey.length > 16) cipherKey = Arrays.copyOf(cipherKey, 16); } rememberMeManager.setCipherKey(cipherKey); return rememberMeManager; }
Example #5
Source File: SecurityModule.java From tapestry-security with Apache License 2.0 | 5 votes |
@SuppressWarnings("rawtypes") @Contribute(Serializer.class) public static void addSafePrincipalTypes(Configuration<Class> configuration) { configuration.add(Long.class); configuration.add(String.class); configuration.add(Integer.class); configuration.add(Number.class); }
Example #6
Source File: SecurityModuleUnitTest.java From tapestry-security with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @BeforeClass public void setUp() { serializer = mock(Serializer.class); when(serializer.serialize(any(Object.class))).thenReturn(new byte[12]); }